import os
import scrapy


class LagouSpider(scrapy.Spider):
    name = "xx"

    def start_requests(self):
        urls = [
            'http://quotes.toscrape.com/page/1/',
            'http://quotes.toscrape.com/page/2/',
            'http://quotes.toscrape.com/page/3/',
            'http://quotes.toscrape.com/page/4/',
            'http://quotes.toscrape.com/page/5/',
            'http://quotes.toscrape.com/page/6/',
            'http://quotes.toscrape.com/page/7/',
            'http://quotes.toscrape.com/page/8/',
            'http://quotes.toscrape.com/page/9/',
            'http://quotes.toscrape.com/page/10/',
        ]
        for url in urls:
            yield scrapy.Request(url, self.parse)

    def parse(self, response):
        bname = 'quotes_%s.html' % response.url.split('/')[-2]
        with open(bname, 'w') as f:
            f.write(response.text)
